import { createStore } from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import tokenModule from './token';
import userModule from './user';

export default createStore({
  modules: {
    token: tokenModule,
    user: userModule
  },
  plugins: [
    createPersistedState({
      storage: {
        getItem: key => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: key => uni.removeStorageSync(key)
      },
      paths: ['token', 'user'] // 持久化所有字段
    })
  ]
});
